local shiren = fk.CreateSkill{
    name = "rmt__shiren",
    dynamic_desc = function (self, player, lang)
        local arr = type(player:getMark("rmt__shiren")) == "table" and player:getMark("rmt__shiren") or {"eight_diagram","slash"}
        local str = "准备阶段，或你受到伤害后，你可以如【"
        str = str .. Fk:translate(arr[1],"zh_CN").."】般视为使用一张【"
        str = str .. Fk:translate(arr[2],"zh_CN").."】。以此判定失败后，你声明一张未声明过的即时牌替换第二个【】内，且均声明过后，第一个【】内改为“闪电”并重置声明牌。"
        return str
    end,
}
Fk:loadTranslationTable{
  ["rmt__shiren"] = "势任",
  [":rmt__shiren"] = "准备阶段，或你受到伤害后，你可以如【八卦阵】般视为使用一张【杀】。以此判定失败后，你声明一张未声明过的即时牌替换第二个【】内，且均声明过后，第一个【】内改为“闪电”并重置声明牌。",
  ["#rmt__shiren"] = "是否发动 势任，如【%arg】般视为使用一张【%arg2】",
  ["#rmt__shiren_choice"] = "势任：声明一种牌名替换第二个【】内的牌名",
  ["@rmt__shiren"] = "势任",
}

local spec = {
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local arr = type(player:getMark("rmt__shiren")) == "table" and player:getMark("rmt__shiren") or {"eight_diagram","slash"}
        local use = room:askToUseVirtualCard(player,{
            name = arr[2],
            skill_name = shiren.name,
            prompt = "#rmt__shiren:::"..arr[1]..":"..arr[2],
            skip = true,
            extra_data = {
                bypass_distances = true,
                bypass_times = true,
                extraUse = true,
            },
        })
        if use then
            event:setCostData(self,use)
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local arr = type(player:getMark("rmt__shiren")) == "table" and player:getMark("rmt__shiren") or {"eight_diagram","slash"}
        local judge = {
            who = player,
            reason = self.name,
            pattern = ".|.|heart,diamond",
        }
        if arr[1] == "lightning" then
            judge = {
                who = player,
                reason = self.name,
                pattern = ".|2~9|spade",
            }
        end
        room:judge(judge)
        local result = judge.card
        if arr[1] == "lightning" and result.suit == Card.Spade and result.number >= 2 and result.number <= 9 then
            room:damage{
                to = judge.who,
                damage = 3,
                damageType = fk.ThunderDamage,
                skillName = self.name,
            }
        end

        if Exppattern:Parse(judge.pattern):match(result) and not player.dead then
            room:useCard(event:getCostData(self))
        else
            local names = Fk:getAllCardNames("bt")
            for _, v in ipairs(player:getTableMark("rmt__shiren_cards")) do
                if table.contains(names,v) then
                    table.removeOne(names,v)
                end
            end
            table.removeOne(names,arr[2])
            if #names > 0 then
                local choice = room:askToChoice(player,{
                    choices = names,
                    skill_name = shiren.name,
                    prompt = "#rmt__shiren_choice",
                })
                arr[2] = choice
                local marks = player:getTableMark("rmt__shiren_cards")
                table.insert(marks,choice)
                room:setPlayerMark(player,"rmt__shiren_cards",marks)
            end
            if #Fk:getAllCardNames("bt") == #player:getTableMark("rmt__shiren_cards") then
                arr[1] = "lightning"
                room:setPlayerMark(player,"rmt__shiren_cards",0)
            end
            room:setPlayerMark(player,"rmt__shiren",arr)
            room:setPlayerMark(player,"@rmt__shiren",table.concat(table.map(arr, Util.TranslateMapper)," "))
        end
    end,
}

shiren:addEffect(fk.EventPhaseStart, {
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(shiren.name) and target == player and player.phase == Player.Start
    end,
    on_cost = spec.on_cost,
    on_use = spec.on_use,
})

shiren:addEffect(fk.Damaged, {
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(shiren.name) and target == player
    end,
    on_cost = spec.on_cost,
    on_use = spec.on_use,
})

shiren:addAcquireEffect(function (self, player, is_start)
    local room = player.room
    local arr = type(player:getMark("rmt__shiren")) == "table" and player:getMark("rmt__shiren") or {"eight_diagram","slash"}
    room:setPlayerMark(player,"rmt__shiren",arr)
    room:setPlayerMark(player,"@rmt__shiren",table.concat(table.map(arr, Util.TranslateMapper)," "))
end)

shiren:addLoseEffect(function (self, player, is_death)
    player.room:setPlayerMark(player,"@rmt__shiren",0)
end)

return shiren